<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Ringo Chan <334258471@qq.com> <http://www.jxlnxx.com>
// +----------------------------------------------------------------------

namespace Home\Controller;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){
        $M_home_data=M('home_data');
        $fields=array('id,product_id,cover_id');
        $f1_list=$M_home_data->where(array('position'=>1))->field($fields)->order('sort DESC')->limit(0,8)->select();
        $f2_list=$M_home_data->where(array('position'=>2))->order('sort DESC')->limit(0,7)->select();
        $f3_list=$M_home_data->where(array('position'=>3))->order('sort DESC')->limit(0,5)->select();
        //$f4_list=$M_home_data->where(array('position'=>4))->order('sort DESC')->limit(0,4)->select();
        //$f5_list=$M_home_data->where(array('position'=>5))->order('sort DESC')->limit(0,4)->select();
        $M_producdt=M('product');
        $f4_list=$M_producdt->limit(0,5)->field('id,price,title')->select();
        foreach($f4_list as &$item){
            $item['image_path']=get_cover(get_table_field($item['id'],'product_id',
                'cover_id','product_image'),'path');
        }
        $f5_list=$M_producdt->limit(0,5)->field('id,price,title')->select();        
        foreach($f5_list as &$item){
            $item['image_path']=get_cover(get_table_field($item['id'],'product_id',
                'cover_id','product_image'),'path');
        }
        
        
        foreach ($f1_list as $key=>$item){
            $item['image_path']=get_cover($item['cover_id'],'path');
            $item['link']=U('product/detail',array('id'=>$item['product_id']));
        }
        foreach ($f2_list as $key=>$item){
            $item['image_path']=get_cover($item['cover_id'],'path');
            $item['link']=U('product/detail',array('id'=>$item['product_id']));
        }
        foreach ($f3_list as $key=>$item){
            $item['image_path']=get_cover($item['cover_id'],'path');
            $item['link']=U('product/detail',array('id'=>$item['product_id']));
        }
        foreach ($f4_list as $key=>$item){
            $item['image_path']=get_cover($item['id'],'path');
            $f4_list[$key]['link']=U('product/detail',array('id'=>$item['product_id']));
        }
        foreach ($f5_list as $key=>$item){
            $item['image_path']=get_cover($item['id'],'path');
            $item['link']=U('product/detail',array('id'=>$item['product_id']));
        }
       
        $f1=array();
        $f1['title']='抢购会';
        $f1['more']=U('Product/index');
        $f1['item']=json_encode($f1_list);
        $this->assign('f1',$f1);
        $f2=array();
        $f2['title']='拍真宝';
        $f2['more']=U('Product/index');
        $f2['item']=json_encode($f2_list);
        $this->assign('f2',$f2);
        
        $f3=array();
        $f3['title']='选礼物';
        $f3['more']=U('Product/index');
        $f3['item']=json_encode($f3_list);
        $this->assign('f3',$f3);
        
        $f4=array();
        $f4['title']='选礼物';
        $f4['more']=U('Product/index');
        $f4['item']=$f4_list;
        $this->assign('f4',$f4);
        
        $f5=array();
        $f5['title']='选礼物';
        $f5['more']=U('Product/index');
        $f5['item']=$f5_list;
        $this->assign('f5',$f5);
        
        $this->display();
    }
    
    

}